<template>
  <div class="box">
    <nav>
      <div
        :class="{ active: i == tapActiveClass }"
        @click="tapChange(v, i)"
        v-for="(v, i) in tapData"
        :key="i"
      >
        {{ v.name }}
      </div>
    </nav>
  </div>
</template>
<script>
export default {
  name: "appTap",
  props: ["tapData"],
  data() {
    return {
      tapActiveClass: 0,
    };
  },
  mounted() {
    this.tapActiveClass = JSON.parse(sessionStorage.getItem("cid")).index || [];
  },
  methods: {
    tapChange(v, i) {
      this.$emit("tapChange", v);
      this.tapActiveClass = i;
      sessionStorage.setItem("cid", JSON.stringify({ cid: v.cid, index: i }));
    },
  },
  components: {},
};
</script>

<style lang="scss">
.box {
  .active {
    background-color: #7a9c2e;
  }
  nav {
    width: 100%;
    height: 4.875rem;
    display: flex;
    justify-content: space-around;
    background-color: #f7f7f7;
    align-items: center;
    flex-wrap: wrap;
  }
}
</style>
